package com.zbkj.admin.controller.course;

import com.zbkj.common.model.course.ActivityLocation;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.PageParamRequest;
import com.zbkj.common.request.course.ActivityLocationRequest;
import com.zbkj.common.request.course.ActivityLocationSearchRequest;
import com.zbkj.common.response.CommonResult;
import com.zbkj.service.service.course.ActivityLocationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 *  前端控制器
 */
@Slf4j
@RestController
@RequestMapping("api/admin/activity-location")
@Api(tags = "") //配合swagger使用

public class ActivityLocationController {

    @Autowired
    private ActivityLocationService activityLocationService;

    /**
     * 分页显示
     * @param request 搜索条件
     * @param pageParamRequest 分页参数
     * @author Mr.guqianbin
     * @since 2022-09-29
     */
    @ApiOperation(value = "分页列表") //配合swagger使用
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<ActivityLocation>>  getList( @Validated ActivityLocationSearchRequest request, @Validated PageParamRequest pageParamRequest){
        CommonPage<ActivityLocation> activityLocationCommonPage = CommonPage.restPage(activityLocationService.getList(request, pageParamRequest));
        return CommonResult.success(activityLocationCommonPage);
    }

    /**
     * 新增
     * @param activityLocationRequest 新增参数
     * @author Mr.guqianbin
     * @since 2022-09-29
     */
    @ApiOperation(value = "新增")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public CommonResult<String> save(@RequestBody @Validated ActivityLocationRequest activityLocationRequest){
        ActivityLocation activityLocation = new ActivityLocation();
        BeanUtils.copyProperties(activityLocationRequest, activityLocation);

        if(activityLocationService.save(activityLocation)){
            return CommonResult.success();
        }else{
            return CommonResult.failed();
        }
    }

    /**
     * 删除
     * @param id Integer
     * @author Mr.guqianbin
     * @since 2022-09-29
     */
    @ApiOperation(value = "删除")
    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    public CommonResult<String> delete(@RequestParam(value = "id") Integer id){
        if(activityLocationService.removeById(id)){
            return CommonResult.success();
        }else{
            return CommonResult.failed();
        }
    }

    /**
     * 修改
     * @param activityLocationRequest 修改参数
     * @author Mr.guqianbin
     * @since 2022-09-29
     */
    @ApiOperation(value = "修改")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public CommonResult<String> update(@RequestBody @Validated ActivityLocationRequest activityLocationRequest){
        ActivityLocation activityLocation = new ActivityLocation();
        BeanUtils.copyProperties(activityLocationRequest, activityLocation);

        if(activityLocationService.updateById(activityLocation)){
            return CommonResult.success();
        }else{
            return CommonResult.failed();
        }
    }

    /**
     * 查询信息
     * @param id Integer
     * @author Mr.guqianbin
     * @since 2022-09-29
     */
    @ApiOperation(value = "详情")
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    public CommonResult<ActivityLocation> info(@RequestParam(value = "id") Integer id){
        ActivityLocation activityLocation = activityLocationService.getById(id);
        return CommonResult.success(activityLocation);
   }
}



